<?php

namespace Modules\Production\Repository;

use Modules\Base\Repository\MaterialRepository;
use Modules\Common\Repository\QrcodeRepository;
use Modules\Production\Models\ReportOrderBox;

class ReportOrderBoxRepository
{

    /**
     * 根据箱号查询一条信息
     * @param $lotnum
     * @return mixed
     */
    static public function getByLotNum($lotnum){
        return ReportOrderBox::where('lot_num',$lotnum)->first();
    }

    /**
     * 查询未入库箱号
     * @param $lotnum
     * @return mixed
     */
    static public function getByLotNumList($lotnum){
        return ReportOrderBox::where('lot_num',$lotnum)->get();
    }

    /**
     * 返回箱号打印数据
     * @param $ids
     * @return mixed
     */
    static public function getPrintDataById($ids){

        $boxList = ReportOrderBox::whereIn('id',$ids)->with(['order','material'])->get()->toArray();

        foreach ($boxList as &$val){

            $productionOrder = ProductionOrderRepository::getOrderById($val['order']['production_id']);

            $val['make_qty']        = $productionOrder->fqty;
            $val['box_url']         = QrcodeRepository::getQrcodeUrl($val['lot_num']);
            $val['material_url']    = QrcodeRepository::getQrcodeUrl($val['material_no']);

        }

        return $boxList;

    }

}
